<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>通知公告列表</title>
</head>
<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">

<link rel="stylesheet" href="../../src/dist/css/page.css">

<body>
<div class="weui-cells news-List">
    <div class="weui-cells__tips">通知公告</div>
    <div class="weui-cells" id="listDemo">
        <img src="../../src/dist/img/nodata.png" alt="" class="nodataImg">
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- Dist -->
<script src="../../src/dist/js/index.js"></script>
<script src="../../src/dist/js/utils.js"></script>
<script src="../../src/dist/js/request.js"></script>
<script>
    var listData = [],
		customid = '';
    $(function(){
        var paras = location.search;            //search获得地址中的参数，内容为'?itemId=12'
        var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
        paras = {};                    //让paras变成没有内容的json对象
        for (i in result) {
            var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
            paras[temp[0]] = temp[1];
        }
		customid = paras.customid;     //根据参数名"itemId"，获取参数值

        //getnotificationList()   //真实接口数据
		getnotificationListPHP() // 本地测试数据
    })

    function getnotificationListPHP() {
        $.ajax({
            type: "POST",
            url: "../../src/php/requestOnline.php",
            data: {
                act: 'CSRQ_getnotificationAnnouncement'
            },
            success: function (data) {
                data = eval('(' + data + ')')
				listData = data
                createListDemo()
            },
            error: function (data) {

            }
        });
	}
    function getnotificationList() {
        get("/wechat/notice/getNotices", {}, function (data) {
            if (data.code === 0) {
				listData = data.data
                if(data.data.length ===0 ){
					$.toast('暂无数据!', 'text');
                	return
                }
                createListDemo()
            } else {
                $.toast('获取通知公告失败!', 'forbidden');
            }
        }, false, true);
	}
	function createListDemo(){
			let d = listData
			let h = ''
			for (let [index, item] of d.entries()) {
				h += '<div class="list-card" onclick="showDetail(\''+item["id"]+'\')">\n' +
                     '  <div class="l-title">'+item['title']+'</div>\n' +
                     '  <div class="l-content">'+item['detail']+'</div>\n' +
                     '  <div class="l-time"><i class="iconfont iconshijian"></i>'+item['overdueTime']+'</div>\n' +
                     '</div>'
			}
			$("#listDemo").html(h)
    }
    function showDetail(id) {
      location.href="./detail.html?id="+id
	}

</script>
</body>
</html>
